package com.atguigu.vod.Utils.aliyunVodUtils;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;

import java.util.List;

public class GetPlayUrlUtils {
    //获取视频地址的方法
    public static String getPlayUrl(String id)  {
        //1.根据视频id获取视频播放地址
        DefaultAcsClient defaultAcsClient = InitObject.initVodClient("LTAI5tSocqfgccE716baKnWE", "LXGmKwTXsvB2b56lxWkC6YSCIRMGj9");
        //创建获取视频地址的request和response
        GetPlayInfoRequest request = new GetPlayInfoRequest();


        //向request对象里面设置视频id
        request.setVideoId(id);

        //调用初始化对象
        GetPlayInfoResponse response = null;
        try {
            response = defaultAcsClient.getAcsResponse(request);

            List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();

            //播放地址
            for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList){
                System.out.println("PlyInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
                return playInfo.getPlayURL();
            }
            //base信息
//            System.out.println("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
        } catch (ClientException e) {
            e.printStackTrace();
        }


        return id;
    }
}
